package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.CaseMapper;
import com.ayou.eggguard.farm.mapper.ChickenShedMapper;
import com.ayou.eggguard.farm.pojo.Case;
import com.ayou.eggguard.farm.service.CaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CaseServiceImpl implements CaseService {
    @Autowired
    private CaseMapper caseMapper;

    @Autowired
    private ChickenShedMapper chickenShedMapper;

    @Override
    public PageBean<Case> getCases(int pageNum, int pageSize, String caseNumber) {
        PageBean<Case> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Case> list=caseMapper.getCases(caseNumber);
        Page<Case> p= (Page<Case>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public void add(Case c) {
        caseMapper.add(c);
        //添加病历的同时鸡舍中的发病数应该增加
        chickenShedMapper.addDiseaseCount(c.getCoopNumber());
    }

    @Override
    public void update(Case c) {
        caseMapper.update(c);
    }

    @Override
    public void delete(Integer id) {
        caseMapper.delete(id);
    }

    @Override
    public List<Map<String, Object>> getCaseFrequency() {
        return caseMapper.getCaseFrequency();
    }

    @Override
    public List<Map<String, Object>> getBlightCount() {
        return caseMapper.getBlightCount();
    }
}
